import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;

import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.Timer;


public class ExamplePanel extends JPanel implements  ActionListener{

	private Timer t;
	private MainCharacter mc;
	
	
	public ExamplePanel(){
		super();
		mc = new MainCharacter();
		t = new Timer(10, this);
		t.addActionListener(mc);
		this.addKeyListener(mc);
		
		this.setBackground(Color.BLACK);
		System.out.println(Arrays.toString(t.getActionListeners()));
		t.start();
	
	}

	
	
	
	
	@Override
	public void paint(Graphics g){
		Graphics2D g2d = (Graphics2D)g;
		super.paint(g2d);
		g2d.setColor(Color.CYAN);
		g2d.drawImage(mc.getImage(), (int)mc.getX(),(int)mc.getY(), null);


		g2d.dispose();

	}

	public static void main(String[] args){
		ExamplePanel ex = new ExamplePanel();
		JFrame frame = new JFrame();
		
		frame.setSize(1024, 720);
		frame.getContentPane().setBackground(Color.BLACK);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.add(ex);
		ex.registerKeyListeners(frame);
		frame.setVisible(true);
	}





	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		this.repaint();
	}

	public void registerKeyListeners(JFrame parent){
		parent.addKeyListener(mc);
	}
	


}
